package com.demo.dao;

import java.util.List;

import org.apache.ibatis.annotations.DeleteProvider;
import org.apache.ibatis.annotations.InsertProvider;
import org.apache.ibatis.annotations.Options;
import org.apache.ibatis.annotations.SelectProvider;
import org.apache.ibatis.annotations.UpdateProvider;

import com.demo.model.Message;

public interface MessageDao {

	// public long insert(Connection conn, Message message) throws SQLException
	// {
	// String sql = "insert into message (content, createTime) values (?,?)";
	// PreparedStatement ps = conn.prepareStatement(sql,
	// Statement.RETURN_GENERATED_KEYS);
	// ps.setString(1, message.getContent());
	// ps.setString(2, message.getCreateTime());
	// ps.execute();
	// ResultSet rs = ps.getGeneratedKeys();
	// while (rs.next()) {
	// return rs.getLong(1);
	// }
	// return 0;
	// }

	@InsertProvider(type = com.demo.dao.mapper.MessageMapper.class, method = "insert")
	@Options(useGeneratedKeys = true, keyProperty = "id", keyColumn = "id")
	public int insert(Message message);

	// public Message selectOne(Connection conn, long id) throws SQLException {
	// String sql = "select * from Message where id=" + id;
	// Statement st = conn.createStatement();
	// ResultSet rs = st.executeQuery(sql);
	// Message message = null;
	// while (rs.next()) {
	// message = new Message();
	// message.setId(rs.getLong("id"));
	// message.setContent(rs.getString("content"));
	// message.setCreateTime(rs.getString("createTime"));
	// }
	// return message;
	// }

	@SelectProvider(type = com.demo.dao.mapper.MessageMapper.class, method = "selectOne")
	public Message selectOne(Long id);

	// public List<Message> selectAll(Connection conn) throws SQLException {
	// String sql = "select * from Message order by id desc";
	// Statement st = conn.createStatement();
	// ResultSet rs = st.executeQuery(sql);
	// Message message = null;
	// List<Message> messages = new ArrayList<>();
	// while (rs.next()) {
	// message = new Message();
	// message.setId(rs.getLong("id"));
	// message.setContent(rs.getString("content"));
	// message.setCreateTime(rs.getString("createTime"));
	// messages.add(message);
	// }
	// return messages;
	// }

	@SelectProvider(type = com.demo.dao.mapper.MessageMapper.class, method = "select")
	public List<Message> select();

	@UpdateProvider(type = com.demo.dao.mapper.MessageMapper.class, method = "update")
	public Integer update(Message message);

	@DeleteProvider(type = com.demo.dao.mapper.MessageMapper.class, method = "delete")
	public Integer delete(Long id);
}
